/* eslint-disable */
export const phoneReg = /^1[3-9]{1}\d{9}$/
export const checkCodeReg = /^\d{6}$/
export const emailReg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
export const numberReg = /^[0-9]+$/
export const idcardReg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

export const pwdReg = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,16}$/
export const pwdReg2 = /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*+=_.()<>?])[\da-zA-Z!@#$%^&*+=_.()<>?]{8,16}$/
export const pwdReg3 =
  /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,16}$/

export const phoneValidCheck = phone => phoneReg.test(phone)
export const userNameValidCheck = userName => {
  if (userName && userName.length) {
    let valid = true
    for (let i = 0; i < userName.length; i++) {
      const itemValid = /^[\u4e00-\u9fa5]|[\w]|[ ]$/.test(userName[i])
      if (!itemValid) {
        valid = false
        break
      }
    }
    return valid
  }
  return false
}

export const stripHTML = val => {
  const reg = /<(?:.|\s)*?>/g
  return val.replace(reg, '')
}

export const replaceTag2Flag = (val, tag, flag) => {
  if (tag) {
    const reg = new RegExp(`<${tag}(?:.|\s)*?>`, 'g')
    return val.replace(reg, flag)
  }
}
